<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

require_once '../resources/org/code/Code.class.php';

class LoginController extends CommonController
{
    public function login()
    {
        if($input = Input::all()){
            //验证验证码
            $code = new \Code;
            $_code = $code->get();
            if(strtoupper($input['code'])!=$_code){
                return back()->with('msg','验证码错误!');
            }
            //验证用户是否存在
            $username = $input['username'];
            $res = DB::table('admin')->where('username',$username)->first();
            if(!$res){
                return back()->with('msg','用户不存在!');
            }
            $pwd = $input['pwd'];
            if(md5($pwd.env('PWD_SALT'))!=$res->pwd){
                return back()->with('msg','密码错误!');
            }
            return redirect('admin/index')->with('msg','登陆成功!');

        }
            return view('admin.login.login');
    }

    public function code()
    {
        $code = new \Code;
        $code->make();
    }

}
